package org.sokula.sun.service.meta;

import java.util.List;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 
 * @author dong.yaojd
 * 
 * @version $Id: $
 */
public class OperationInfo {

	private String name;

	private List<ParameterInfo> parameters;

	private ReturnInfo returnInfo;

	private List<ExceptionInfo> exceptionInfo;

	public List<ExceptionInfo> getExceptionInfo() {
		return exceptionInfo;
	}

	public void setExceptionInfo(List<ExceptionInfo> exceptionInfo) {
		this.exceptionInfo = exceptionInfo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<ParameterInfo> getParameters() {
		return parameters;
	}

	public void setParameters(List<ParameterInfo> parameters) {
		this.parameters = parameters;
	}

	public ReturnInfo getReturnInfo() {
		return returnInfo;
	}

	public void setReturnInfo(ReturnInfo returnInfo) {
		this.returnInfo = returnInfo;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("parameters", this.parameters)
				.append("name", this.name).append("exceptionInfo",
						this.exceptionInfo).append("returnInfo",
						this.returnInfo).toString();
	}

	public String toServiceHtml() {
		StringBuffer buff = new StringBuffer();
		buff.append(this.returnInfo.getType().getName()).append(" ").append(this.name)
				.append("(");
		if(null != parameters){
			int i =0  ;
			int size = parameters.size();
			for(ParameterInfo pi : parameters){
				buff.append(pi.getTypeName());
				if(i < size -1){
					buff.append(",");
				}
				i ++;
			}
		}
		buff.append(")");
		if(null != exceptionInfo){
			int i =0  ;
			int size = exceptionInfo.size();
			for(ExceptionInfo pi : exceptionInfo){
				buff.append(pi.getTypeName());
				if(i < size -1){
					buff.append(",");
				}
				i ++;
			}
		}
		return buff.toString();
	}

}
